package com.glacier.excel.domain;

import com.glacier.excel.domain.builder.HeaderMetaBuilder;
import com.glacier.excel.domain.builder.SheetMetaBuilder;
import com.glacier.excel.utils.ClassUtils;

import java.util.List;
import java.util.stream.Collectors;

/**
 * date 2021-06-17 11:05
 *
 * @author glacier
 * @version 1.0
 */
public class SheetMetaFactory {
    
    private SheetMetaFactory() {
    
    }
    
    public static <T> SheetMeta buildSheetMeta(String title, String explain, Class<T> clazz) {
        return buildSheetMeta(title, title, explain, clazz);
    }
    
    public static <T> SheetMeta buildSheetMeta(String sheetName, String title, String explain, Class<T> clazz) {
        return SheetMetaBuilder.aSheetMeta()
                .withTitle(sheetName)
                .withTitle(title)
                .withExplain(explain)
                .withHeaderMetas(
                        ClassUtils.analysisField(clazz)
                                .stream()
                                .map(excelPropertyMeta ->
                                        HeaderMetaBuilder.aHeaderMeta()
                                                .build())
                                .collect(Collectors.toList()))
                .build();
    }
    
    public static SheetMeta buildSheetMeta(String sheetName, String title, String explain, List<HeaderMeta> headerMetas) {
        return SheetMetaBuilder.aSheetMeta()
                .withTitle(title)
                .withSheetName(sheetName)
                .withExplain(explain)
                .withHeaderMetas(headerMetas)
                .build();
    }
}
